clear all
use covid_working_data

***Drop earlier years and last few days
drop if year==2020 & month==4
drop if year==2017|year==2018

**Table 6
reghdfe lspend covid, ab(month day dow gvkey cat_code) vce(cluster gvkey )
outreg2 using "Output/Tables/COVID_Churn_total.tex", title() keep() tex(landscape pr frag) drop() label addtext(Month/Day/DoW FE, YES, Firm FE, YES, Month*Beta Control, NO, Month*Size Control, NO, Industry*Month FE, NO) ctitle("ln(Spend)") nocons replace

reghdfe lspend covid covid_X_chshare, ab(month day dow gvkey cat_code) vce(cluster gvkey month)
outreg2 using "Output/Tables/COVID_Churn_total.tex", title() keep() tex(landscape pr frag) drop() label addtext(Month/Day/DoW FE, YES, Firm FE, YES, Month*Beta Control, NO, Month*Size Control, NO, Industry*Month FE, NO) ctitle("ln(Spend)") nocons 

reghdfe lspend covid covid_X_chshare covid_X_beta covid_X_avg_spend, ab(month day dow gvkey cat_code) vce(cluster gvkey month)
outreg2 using "Output/Tables/COVID_Churn_total.tex", title() keep() tex(landscape pr frag) drop(covid_X_beta covid_X_avg_spend) label addtext(Month/Day/DoW FE, YES,  Firm FE, YES, Month*Beta Control, YES, Month*Size Control, YES, Industry*Month FE, NO) ctitle("ln(Spend)") nocons 

reghdfe lspend  covid_X_chshare, ab(month day dow gvkey cat_code cat_X_month) vce(cluster gvkey month)
outreg2 using "Output/Tables/COVID_Churn_total.tex", title() keep() tex(landscape pr frag) drop() label addtext(Month/Day/DoW FE, YES, Firm FE, YES, Month*Beta Control, NO, Month*Size Control, NO, Industry*Month FE, YES) ctitle("ln(Spend)") nocons 

reghdfe lspend  covid_X_chshare covid_X_beta covid_X_avg_spend, ab(month day dow gvkey cat_X_month) vce(cluster gvkey month)
outreg2 using "Output/Tables/COVID_Churn_total.tex", title() keep() tex(landscape pr frag) drop(covid_X_beta covid_X_avg_spend) label addtext(Month/Day/DoW FE, YES, Firm FE, YES, Month*Beta Control, YES, Month*Size Control, YES, Industry*Month FE, YES) ctitle("ln(Spend)") nocons 


***Figure A.8
***Make event study/distributed lag approach as suggested by referee
**Normalize spending by firm
egen mean_spend = mean(total_spend), by(gvkey)
gen norm_spend = total_spend/mean_spend

drop if chshare==.

**Make churn quantiles, stripping out industry variation
reg chshare i.cat_code
predict chshare_resid, resid
xtile churn_xtile = chshare_resid, nquantiles(4)

gen week = wofd(date)
gen week_of_year = week(date)
format week %tw

collapse norm_spend, by(week week_of_year year churn_xtile)

**Strip out seasonality
reg norm_spend i.week_of_year
predict norm_spend_resid, resid

twoway (line norm_spend_resid week if churn_xtile==1)(line norm_spend_resid week if churn_xtile==2)(line norm_spend_resid week if churn_xtile==3) if (year==2020|(year==2019 & week_of_year>=15)), legend(lab(1 "Low Churn") lab(2 "Med Churn") lab(3 "High Churn"))
graph export "Output/COVID_TimeSeries.png", height(600) width(900) replace


